package com.kuaimacode.kframework.admin.controller.master;

import com.github.pagehelper.PageInfo;
import com.kuaimacode.kframework.admin.services.account.UserAccountDetailServices;
import com.kuaimacode.kframework.admin.services.master.MasterDrawApplyService;
import com.kuaimacode.kframework.admin.services.user.UserService;
import com.kuaimacode.kframework.admin.vo.request.MasterReq;
import com.kuaimacode.kframework.constants.PageConstants;
import com.kuaimacode.kframework.mybatis.models.user.MasterAccountResult;
import com.kuaimacode.kframework.mybatis.models.user.UserAccountDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author 12786 on 2019/5/25.
 * @version 1.0
 */
@Controller
@RequestMapping({"/masteraccount"})
public class MasterAccountBalanceController {

    private static String PAGE_FILE_NAME = "masterdraw/";

    @Autowired
    private MasterDrawApplyService drawApplyService;

    @Autowired
    private UserAccountDetailServices detailServices;

    @Autowired
    private UserService userService;

    /**
     * 余额列表
     * @param pageNum
     * @param pageSize
     * @param masterReq
     * @param model
     * @return
     */
    @RequestMapping(value = {"/index"})
    public String index(@RequestParam(value = "pageNum", required = true, defaultValue = PageConstants.PAGE_NUM+"") int pageNum,
                        @RequestParam(value = "pageSize", required = true, defaultValue = PageConstants.PAGE_SIZE+"") int pageSize,
                        MasterReq masterReq, ModelMap model) {
        PageInfo<MasterAccountResult> pageInfo = drawApplyService.getMasterAccount(masterReq,pageNum, pageSize);
        // pageInfo.list master
        model.put("pageInfo", pageInfo);
        model.put("masterReq", masterReq);
        return PAGE_FILE_NAME + "index";
    }

    /**
     * 余额明细
     * @param pageNum
     * @param pageSize
     * @param model
     * @return
     */
    @RequestMapping(value = {"/detail/{userId}"})
    public String detail(@RequestParam(value = "pageNum", required = true, defaultValue = PageConstants.PAGE_NUM+"") int pageNum,
                         @RequestParam(value = "pageSize", required = true, defaultValue = PageConstants.PAGE_SIZE+"") int pageSize,
                         @PathVariable long userId, ModelMap model) {
        PageInfo<UserAccountDetail> pageInfo = detailServices.getUserAccountDetail(userId,pageNum, pageSize);
        // pageInfo.list master
//        MasterReq masterReq = new MasterReq();
        model.put("pageInfo", pageInfo);
        model.put("userId", userId);
        return PAGE_FILE_NAME + "detail";
    }

}
